<?php

class Users3_Notification_model extends CI_Model {

    public $table = "";
    //put your code here
    function __construct() {
        parent::__construct();
        $this->table = MYSQL_TABLE_PREFLIX.TABLE_USER3_NOTIFICATION;
    }

    function GetAll($offset = 0, $limit = 10) {
        $this->db->from($this->table);
        $this->db->order_by("PostDate", "asc");
        $this->db->limit($limit,$offset);
        $query = $this->db->get();
        return $query->result_array();
    }
    
    function Get($data){
        $query = $this->db->get_where($this->table, $data);
        return $query->result_array();
    }
    
    function Get_Advanced($select = '*', $where = array(), $order_by = "", $limit = 10, $offset = 0){
        $query = $this->db->select($select)->order_by($order_by)->get_where($this->table, $where,$limit, $offset);
        return $query->result_array();
    }

    function Insert($data) {
        $this->db->insert($this->table, $data);
    }
    
    function Insert_Noti($data,$Additional,$Picture = 'assets/images/notification.png'){
        $this->Insert($data);
        $max_id = $this->Get_Max();
        
        $Link = 'user_group3/notification/'.$max_id.'?';
        foreach($Additional as $Ad){
            $Link .= 'Additional[]='.$Ad;
        }
        
        $this->Update(array('LinkTo'    =>  $Link,'PictureURL'  =>  $Picture),
                array('NotiID' => $max_id));
    }
    
    function Update($data, $where)  {
        $this->db->where($where);
        $this->db->update($this->table,$data);
    }
    
    function Get_Max($data = "NotiID")  {
        $this->db->select_max($data);
        $query = $this->db->get($this->table);
        $query = $query->result_array();
        $query = $query[0]['NotiID'];
        return $query;
    }

}
